package com.hhf.cloud.controller;

import com.hhf.cloud.resp.Result;
import com.hhf.cloud.service.StorageTccService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Daniel-黄海峰
 * @Description
 * @create 2024/3/3 17:01
 */
@RestController
public class StorageTccController {
    @Autowired
    private StorageTccService storageTccService;

    /**
     * 扣减库存
     * 不懂TCC的，请看详细文档：https://seata.apache.org/zh-cn/blog/seata-tcc/
     */
    @PostMapping(value = "/storage/decreasetcc")
    Result<Boolean> decreaseTcc(@RequestParam("productId") Long productId, @RequestParam("count") Integer count) {
        boolean ret = storageTccService.decreaseTcc(null, productId, count);
        return Result.success(ret);
    }
}
